<?php
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */

// @codingStandardsIgnoreFile

/** @var $block \Magento\Swatches\Block\Adminhtml\Attribute\Edit\Options\Text */

$stores = $block->getStoresSortedBySortOrder();
?>
<fieldset class="fieldset">
    <legend class="legend">
        <span><?php echo $block->escapeHtml(__('Manage Swatch (Values of Your Attribute)')) ?></span>
    </legend>
    <div id="swatch-text-options-panel">
        <table class="data-table clearfix" cellspacing="0">
            <thead>
            <tr id="swatch-text-options-table">
                <th class="col-draggable"></th>
                <th class="col-default"><span><?php echo $block->escapeHtml(__('Is Default')) ?></span></th>
                <?php foreach ($stores as $_store): ?>
                    <th class="col-swatch col-<%- data.id %>
                        <?php if ($_store->getId() == \Magento\Store\Model\Store::DEFAULT_STORE_ID): ?> _required<?php endif; ?>"
                        colspan="2">
                        <span><?php echo $block->escapeHtml($_store->getName()) ?></span>
                    </th>
                <?php endforeach; ?>
                <?php $colTotal = count($stores) * 2 + 3; ?>
                <th class="col-delete">&nbsp;</th>
            </tr>
            </thead>
            <tbody data-role="swatch-text-options-container" class="ignore-validate"></tbody>
            <tfoot>
            <tr>
                <th colspan="<?php echo (int)$colTotal; ?>">
                    <input type="hidden" class="required-text-swatch-entry" name="text_swatch_validation"/>
                    <input type="hidden" class="required-text-swatch-unique" name="text_swatch_validation_unique"/>
                </th>
            </tr>
            <tr>
                <th colspan="<?php echo (int)$colTotal; ?>" class="col-actions-add">
                    <?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()):?>
                        <button id="add_new_swatch_text_option_button"
                                title="<?php echo $block->escapeHtml(__('Add Swatch')); ?>"
                                type="button" class="action- scalable add">
                            <span><?php echo $block->escapeHtml(__('Add Swatch')); ?></span>
                        </button>
                    <?php endif; ?>
                </th>
            </tr>
            </tfoot>
        </table>
        <input type="hidden" id="swatch-text-option-count-check" value="" />
    </div>
    <script id="swatch-text-row-template" type="text/x-magento-template">
        <tr>
            <td class="col-draggable">
                <?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()): ?>
                    <div data-role="draggable-handle"
                         class="draggable-handle"
                         title="<?php echo $block->escapeHtml(__('Sort Option')); ?>"></div>
                <?php endif; ?>
                <input data-role="order" type="hidden" name="optiontext[order][<%- data.id %>]"
                       value="<%- data.sort_order %>"
                    <?php if ($block->getReadOnly() || $block->canManageOptionDefaultOnly()): ?> disabled="disabled"<?php endif; ?>
                />
            </td>
            <td class="col-default">
                <input class="input-radio"
                       type="<%- data.intype %>"
                       name="defaulttext[]"
                       value="<%- data.id %>" <%- data.checked %><?php if ($block->getReadOnly()):?>disabled="disabled"<?php endif;?>/>
            </td>
            <?php foreach ($stores as $_store): ?>
                <?php $storeId = (int)$_store->getId(); ?>
                <td class="col-swatch col-<%- data.id %>">
                    <input class="input-text
                        swatch-text-field-<?php /* @noEscape */ echo $storeId; ?>
                        <?php if ($storeId == \Magento\Store\Model\Store::DEFAULT_STORE_ID): ?> required-option required-unique<?php endif; ?>"
                           name="swatchtext[value][<%- data.id %>][<?php /* @noEscape */ echo $storeId; ?>]"
                           type="text" value="<%- data.swatch<?php /* @noEscape */ echo $storeId; ?> %>"
                           placeholder="<?php echo $block->escapeHtml(__("Swatch")); ?>"/>
                </td>
                <td class="swatch-col-<%- data.id %>">
                    <input name="optiontext[value][<%- data.id %>][<?php /* @noEscape */ echo $storeId; ?>]"
                           value="<%- data.store<?php /* @noEscape */ echo $storeId; ?> %>"
                           class="input-text<?php if ($storeId == \Magento\Store\Model\Store::DEFAULT_STORE_ID): ?> required-option<?php endif; ?>"
                           type="text" <?php if ($block->getReadOnly() || $block->canManageOptionDefaultOnly()):?> disabled="disabled"<?php endif;?>
                           placeholder="<?php echo $block->escapeHtml(__("Description")); ?>"/>
                </td>
            <?php endforeach; ?>
            <td id="delete_button_swatch_container_<%- data.id %>" class="col-delete">
                <input type="hidden" class="delete-flag" name="optiontext[delete][<%- data.id %>]" value="" />
                <?php if (!$block->getReadOnly() && !$block->canManageOptionDefaultOnly()):?>
                    <button title="<?php echo $block->escapeHtml(__('Delete')); ?>" type="button"
                            class="action- scalable delete delete-option">
                        <span><?php echo $block->escapeHtml(__('Delete')); ?></span>
                    </button>
                <?php endif;?>
            </td>
        </tr>
    </script>
    <script type="text/x-magento-init">
        {
            "*": {
                "Magento_Swatches/js/text": <?php /* @escapeNotVerified */ echo $block->getJsonConfig(); ?> ,
                "Magento_Catalog/catalog/product/attribute/unique-validate": {
                    "element": "required-text-swatch-unique",
                    "message": "<?php echo $block->escapeHtml(__("The value of Admin must be unique.")); ?>"
                }
            }
        }
    </script>
</fieldset>
